package com.zjl.hiring.company.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zjl.hiring.common.Constant;
import com.zjl.hiring.company.dao.ApplicationDao;

public class ApplicationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ApplicationDao applicationDao = new ApplicationDao();

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// 解决乱码问题
		request.setCharacterEncoding("UTF-8");
		String command = request.getParameter("command");
		if ("deleteApplication".equals(command)) {
			deleteApplication(request, response);
		}
	}

	private void deleteApplication(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		// 获取参数
		int applicationId = Integer.parseInt(request
				.getParameter("applicationId"));
		// 调用业务逻辑
		int row = applicationDao.deleteApplication(applicationId);
		if (row != 1) {
			response.sendRedirect("TalentServlet?command=main&resulr="
					+ Constant.OPERATE_ERROR);
		} else {
			response.sendRedirect("TalentServlet?command=main&result="
					+ Constant.OPERATE_SUCCESS);
		}
	}
}
